package com.lightjet.macross.base.upms.config;

import com.lightjet.macross.common.util.JwtUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

/**
 * @author : lijia
 * @version : 1.0 2020-05-15 10:57
 * description : 管理接口Feign配置类
 */
@Configuration
public class AdminFeignConfig implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        requestTemplate.header("admin-token", JwtUtil.signWithClaims(5,"802sastcasc!", new HashMap<String,String>(){
            {put("adminkey","pohigh");}
            {put("client","base-upms");}
        }));
    }
}
